<template>
	<view class="container bg-w">
		<view class="header uni-flex uni-row flex-between">
			<uni-nav-bar title="施工审核">
				<template slot='left'>
					<view class="flex width-100">
						<i class='iconfont iconfanhui' @click='goBack()'></i>
					</view>
				</template>
				<template slot='right'>
					<i class='iconfont iconshaixuan right-i' @click="open"></i>
				</template>
			</uni-nav-bar>
		</view>
		<view class="position-r-top">
			<uni-search-bar :radius="100" @confirm="searchName" @cancel="cancelName" placeholder="请输入项目名称"></uni-search-bar>
			<view class="buildList" v-if="productData.length > 0">
				<view class="project-total">共{{ total }}个项目</view>
				<view class="project-card" v-for="(item,index) in productData" :key="index"> 
					<view class="project-card__head" @click="goToProjectInfo(item)">
						<view class="title">{{ item.projectName }}</view>
						<view class="state">
							<text>项目详情</text>
							<uni-icons type="arrowright" color="#09aae9"/>
						</view>
					</view>
					<view class="project-card__body">
						<view>
							<text>期次：{{ item.buildPeriodDesc }}</text>
							<text>标段：{{ item.tendersDesc }}</text>
							<text>状态：{{ item.statusDesc }}</text>
						</view>
						<text>地址：{{ item.completeDistrict }}</text>
					</view>
					<view class="project-card__foot">
						<view @click="goToChildProject(item)">查看子项({{ item.subProjectCount }})</view>
						<view @click="goToWaitAuditData(item)">待审核任务<text class="badge">{{ item.countAudit }}</text></view>
					</view>
				</view>
				<!-- <uni-list>
				    <uni-list-item v-for="(item,index) in productData" :key="index" showArrow link :to="'/pages/Application/ConstructionAudit/ConstructionProject/ConstructionProject?projectId='+item.projectId+'&projectName='+item.projectName">
							<template slot='body'>
								<view class="buildList-body">
									<view class="color-6 flex algin-i-c"> <view>项目名称：</view><text class="wid-80 txtCut1">{{item.projectName}}</text></view>
									<view class="color-6 flex algin-i-c"> <view>状态：</view><text class="wid-80 txtCut1">{{item.statusDesc}}</text></view>
								</view>
							</template>
						</uni-list-item>
				</uni-list> -->
			</view>
			<view class="nodata" v-else>
				<text>暂无数据</text>
			</view>
		</view>
		<view class="">
			<uni-popup ref="popup" type="bottom">
				<view class="screen-popup">
					<view class="screen-popup-title flex flex-between">
						<text class="margin-l-10"> 筛选 </text>
						<view class="flex border-left">
							<text @click="close()">取消</text>
							<text @click="screenSubmit()">确认</text>
						</view>
					</view>
					<view class="screen-popup-body">
						<view class="">
							<text>区域</text>
							<uni-group>
								<area-select :districtCode.sync="districtCode"></area-select>
							</uni-group>
						</view>
						<view class="">
							<text>期次</text>
							<uni-group>
								<uni-data-checkbox mode="tag" multiple v-model="buildPeriod" :localdata="periodList"></uni-data-checkbox>
							</uni-group>
						</view>
						<view class="">
							<text>标段</text>
							<uni-group>
								<uni-data-checkbox mode="tag" multiple v-model="tenders" :localdata="tendersData"></uni-data-checkbox>
							</uni-group>
						</view>
						<view class="">
							<text>状态</text>
							<uni-group>
								<uni-data-checkbox mode="tag" multiple v-model="projectStatus" :localdata="projectStatusList"></uni-data-checkbox>
							</uni-group>
						</view>
					</view>
				</view>
			</uni-popup>
		</view>
	</view>
</template>

<script>
	import { findProjects, countSubProject, countAudit } from '@/common/api/ConstructionAudit'
	import { period, projectStatus, section } from '@/common/api/api.js'
	export default {
		data() {
			return {
				productData: [],
				page: {
					pageNo: 1,
					pageSize: 10,
				},
				total: 0,
				totalPage: 0,
				periodList:[],
				tendersData: [],
				projectStatusList:[],
				buildPeriod:[],	//期次
				tenders: [],	//标段
				projectStatus:[],	//项目状态
				districtCode: ''	//地区编码
			}
		},
		onLoad() {
			period().then(res => {
				if(res.code == 20000){
					res.data.forEach(obj => {
						this.periodList.push({
							text: obj.label,
							value: obj.id
						})
					})
				}
			})
			section().then(res => {
				if(res.code == 20000){
					res.data.forEach(obj => {
						this.tendersData.push({
							text: obj.label,
							value: obj.id
						})
					})
				}
			})
			projectStatus().then(res => {
				if(res.code == 20000){
					for (let i in res.data) {
						this.projectStatusList.push({
							text: res.data[i],
							value: i
						})
					}
				}
			})
		},
		onShow() {
			this.productData = [];
			this.loadProductList();
		},
		methods: {
			goToProjectInfo(item) {
				uni.navigateTo({
				  url: `/pages/Application/ConstructionReport/ConstructionProject/ProjectReport/BasicInformation/BasicInformation?projectId=${item.projectId}`
				});
			},
			goToChildProject(item){
				uni.navigateTo({
				  url: `/pages/Application/ConstructionAudit/ConstructionProject/ConstructionProject?projectId=${item.projectId}&projectName=${item.projectName}`
				});
			},
			goToWaitAuditData(item) {
				uni.navigateTo({
				  url: `/pages/Application/ConstructionAudit/ConstructionProject/ProjectAudit/AwaitAuditData/AwaitAuditData?projectId=${item.projectId}`
				});
			},
			loadProductList(){
				findProjects(this.page).then((res)=>{
					if(res.data&&res.data.records.length != 0){
						let projectIdArr = [];
						let data = res.data.records;
						this.total = res.data.total;
						this.totalPage = res.data.pages;
						data.forEach((item)=> {
							projectIdArr.push(item.projectId);
						})
						countAudit(projectIdArr).then((res)=>{
							if(res.code == 20000){
								data.forEach((item)=> {
									this.$set(item, 'countAudit', res.data[item.projectId]||0);
								})
							}
						})
						countSubProject(projectIdArr).then((res)=> {
							if(res.code == 20000){
								data.forEach((item)=> {
									this.$set(item, 'subProjectCount', res.data[item.projectId]||0);
								})
							}
						})
						this.productData = this.productData.concat(res.data.records);
					}
				})
			},
			searchName(e){
				this.productData = [];
				this.page.pageNo = 1;
				this.page.projectName = e.value
				this.loadProductList()
			},
			cancelName(){
				this.productData = [];
				this.page.pageNo = 1;
				this.page.projectName = '';
				this.loadProductList()
			},
			open(){
				this.districtCode = '';
				this.$refs.popup.open()
			},
			close(){
				this.$refs.popup.close()
			},
			screenSubmit(){
				this.productData = [];
				this.page.pageNo = 1;
				this.districtCode? this.page.districtCode = this.districtCode: delete this.page.districtCode;
				this.buildPeriod.length? this.page.buildPeriod = this.buildPeriod: delete this.page.buildPeriod;
				this.tenders.length? this.page.tenders = this.tenders: delete this.page.tenders;
				this.projectStatus.length? this.page.projectStatus = this.projectStatus: delete this.page.projectStatus;
				this.loadProductList();
				this.close();
			},
			onReachBottom() { //上拉加载更多
				this.page.pageNo++
				if (this.page.pageNo <= this.totalPage) {
					this.loadProductList();
				}
			},
			onPullDownRefresh(){//下拉刷新
				this.page.pageNo = 1;
				this.productData = [];
				this.loadProductList();
				setTimeout(function () {
						uni.stopPullDownRefresh();
				}, 1000);
			},
		}
	}
</script>

<style lang="less">
	.uni-searchbar{background-color: #F2F2F2;}
	.buildList{
		padding: 0 16rpx 16rpx;
		background: #f9f9f9;
		.project-total{
			padding: 14rpx;
			text-align: center;
			color: #aaa;
		}
		.project-card{
			margin-bottom: 16rpx;
			color: #8C8C8C;
			border-radius: 10rpx;
			background: #fff;
			box-shadow: 0px 0px 5px rgba(0,0,0,.3);
			>.project-card__head{
				display: flex;
				height: 64rpx;
				line-height: 64rpx;
				color: #333;
				border-bottom: 1px solid #D6D6D6;
				border-radius: 10rpx 10rpx 0 0;
				>.title{
					flex: 1;
					padding: 0 20rpx;
					font-weight: bold;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}
				>.state{
					width: 150rpx;
					color: #09aae9;
					text-align: center;
					>.uni-icons{
						/deep/ span{
							font-size: 30rpx;
						}
					}
				}
			}
			>.project-card__body{
				padding: 10rpx 20rpx 0 36rpx;
				>view{
					display: flex;
					justify-content: space-between;
				}
				text{
					position: relative;
				}
				text:before {
					content: '';
					position: absolute;
					top: 14rpx;
					left: -18rpx;
					display: block;
					width: 6rpx;
					height: 6rpx;
					border-radius: 50%;
					border: 1px solid #09aae9;
					background: #09aae9;
				}
			}
			>.project-card__foot{
				display: flex;
				padding: 20rpx 0;
				justify-content: space-evenly;
				>view{
					width: 250rpx;
					height: 60rpx;
					line-height: 60rpx;
					text-align: center;
					color: #fff;
					border-radius: 10rpx;
					background: #09aae9;
					>.badge{
						display: inline-block;
						min-width: 40rpx;
						height: 40rpx;
						margin-left: 4rpx;
						line-height: 40rpx;
						color: #fff;
						background: #ff0000;
						border-radius: 50%;
						/deep/ span{
							font-size: 24rpx;
						}
					}
				}
			}
		}
		.buildList-body{
			width: 90%;
			>view:first-child{
				margin-bottom: 20rpx;
			}
			>view{
				> view{
					width: 160rpx;
					text-align-last: justify;
				}
			}
		}
	}
	.screen-popup{
		background-color: #fff;
		min-height: 600rpx;
		.screen-popup-title{
			background-color: #f2f2f2;
			height: 100rpx;
			line-height: 100rpx;
			color: #666;
			>view{
				text{
					display: block;
					padding: 0 40rpx;
					line-height: 100rpx;
				}
				text:last-child{
					background-color: #09AAE9;
					color: #fff;
				}
			}
		}
	}
	.screen-popup-body{
		/deep/ .is-tag-checked{
			border-color: #09AAE9;
			background-color: #09AAE9;
		}
		/deep/ .uni-group__content{
			padding: 0 30rpx;
		}
		/deep/ .is-tag{
			padding: 10rpx 0;
			width: 18.4%;
			margin-right: 2%;
			box-sizing: border-box;
			
		}
		/deep/ .is-tag:nth-child(5n){
			margin-right: 0;
		}
		/deep/ .checklist-text{display: block;width: 100%;text-align: center;}
		>view{
			text{
				display: block;
				margin-top: 20rpx;
				margin-left: 3%;
				color: #09AAE9;
			}
		}
	}
</style>
